<%@page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*,java.text.*"%>
<%@ include file="../Connections/ConsorcioSQL7.jsp" %>
<HTML>
<HEAD>
<TITLE>Informacion General Terreno</TITLE><!-- Lotus-Domino (Release 5.0.7 - March 21, 2001 on Windows NT/Intel) -->
	<link rel="stylesheet" href="../css/arastyle.css" type="text/css">
	<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">

<%
String clave1 = request.getParameter("clave");
//out.println("clave!-->" + clave1);
%>
<SCRIPT language=JavaScript>
<!-- 
	function HacerCotizacionPaso2() {
		var cve = '<%=session.getAttribute("Cve_Vendedor")%>' ;
		if( cve != 'null' ){
			top.location.href = 'HacerCotizacionDosNuevo.jsp?clave=<%=clave1%>';
		}else{
			alert("Debe de tener clave de vendedor para poder cotizar!!!");
		}
	}

//-->
</SCRIPT>	
</HEAD>

<BODY rightmargin="0" link="#FFFF99" vlink="#FFFF99" alink="#FFFF99" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" class="fondo">
<FORM>
<%
NumberFormat nf  = new DecimalFormat("#,###.##");
nf.setMinimumFractionDigits(2);
String Usuario = (String) session.getAttribute("User");
//out.println("Usuario ---> " + Usuario);
String Id_Usuario = (String) session.getAttribute("IdUser");
//out.println("Id_Usuario ---> " + Id_Usuario);

String fraccsession = (String) session.getAttribute("fracc");
String CveVendedor = (String)session.getAttribute("Cve_Vendedor");
//out.println("fraccsession ---> " + fraccsession);

//variables
String fracc = "0";
String clave = "";
String no_terreno = "";
String superficie = "";
String precio_m2 = "";
double precio_total = 0.0;
String plano_terreno = "";
String medid_norte = "";
String medid_sur = "";
String medid_oriente = "";
String medid_poniente = "";
String mlcon_norte = "";
String mlcon_sur = "";
String mlcon_oriente = "";
String mlcon_poniente = "";
String statusVtas= "";
boolean bloqueado = false;
Driver DriverRs = (Driver)Class.forName(DRIVER_SQL7).newInstance();
Connection ConnRs = DriverManager.getConnection(URLSTRING_SQL7,USERNAME_SQL7,PASSWORD_SQL7);
String query = "";
PreparedStatement StatementRs = null;
ResultSet Rsquery = null;
boolean Rsquery_isEmpty = true;
boolean Rsquery_hasData = !Rsquery_isEmpty;
Object Rsquery_data;

if (clave1!=null && !clave1.equals("")) {
	query = 
	" SELECT DISTINCT  "+
	"	D.idLote,  "+
	"	D.idDesarrollo,  "+
	"	D.Coto,  "+
	"	D.Manzana,  "+
	"	D.NoLote, "+
	"	D.LinderoNte as LNte,  "+
	"	D.ColindanciaNte as CNte,  "+
	"	D.LinderoSur as LSur,  "+
	"	D.ColindanciaSur as CSur,  "+
	"	D.LinderoOte as LOte,  "+
	"	D.ColindanciaOte as COte,  "+
	"	D.LinderoPte as LPte,  "+
	"	D.ColindanciaPte as CPte, "+
	"	D.Superficie,  "+
	"	D.PrecioXMt,  "+
	"	D.StaVenta, "+
	"	case  "+
	"		when Bloqueado is null then 'D' "+
	"		else Bloqueado "+
	"	end as Bloqueado, "+
	" idLote as Clave,'tertipo1.gif' AS plano_terreno  "+
	" FROM lotes D  "+
	" WHERE idLote = '"+clave1+"'";
	//out.print("<br> QUERY "+query);
	StatementRs = ConnRs.prepareStatement(query);
	Rsquery = StatementRs.executeQuery();
	Rsquery_isEmpty = !Rsquery.next();
	Rsquery_hasData = !Rsquery_isEmpty;
	if (Rsquery_hasData) {
		fracc = Rsquery.getString("idDesarrollo");
		clave = Rsquery.getString("idLote");
		no_terreno = Rsquery.getString("NoLote");
		superficie = Rsquery.getString("Superficie");
		precio_m2 = Rsquery.getString("PrecioXMt");
		statusVtas = Rsquery.getString("StaVenta");
		bloqueado = Rsquery.getString("Bloqueado").equals("B")?true:false;
		String vacia ="";
		//if (superficie!=null || !superficie.equals(vacia) && precio_m2!=null || !precio_m2.equals(vacia)) {
		if (superficie!=null && precio_m2!=null) {
			precio_total =( Double.parseDouble(precio_m2.trim())* Double.parseDouble(superficie.trim()) );
		}
		else precio_total = 0.0;
		plano_terreno = Rsquery.getString("plano_terreno");
		//out.println("<br> plano : " + plano_terreno);
		//instalaciones = Rsquery.getString("instalaciones");
		//caracteristicas = Rsquery.getString("caracteristicas");
		//MEDIDAS	
		medid_norte = nf.format(Rsquery.getDouble("LNte"));
		medid_sur = nf.format(Rsquery.getDouble("LSur"));
		medid_oriente = nf.format(Rsquery.getDouble("LOte"));
		medid_poniente = nf.format(Rsquery.getDouble("LPte"));
		mlcon_norte = Rsquery.getString("CNte");
		mlcon_sur = Rsquery.getString("CSur");
		mlcon_oriente = Rsquery.getString("COte");
		mlcon_poniente = Rsquery.getString("CPte");
	}else{
		out.println("<script>");
		out.println("alert('Terreno no encontrado!!');");
		out.println("window.close();");
		out.println("</script>");
		return;
	}
}
//if (request.getParameter("CveLote")!=null){
%>
<!--<p><img src="/lotificacion/Imagenes/logoCT.jpg"></p>-->
<%
//}else{
%>
<table width="100%" height="100%" border="1" align="center" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
  <tr>
    <td align="center">
	 <table width="100%" height="100%" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <%
    //out.println("<br>imgterr : " + plano_terreno);
    //out.println("<br>fracc.trim() : " + fracc.trim());
   if (!plano_terreno.equals(fracc.trim())) {
   %>
    <td width="27%" rowspan="1" align="center" valign=top><img src="../images/tertipo1.gif"></td>
	<%
    } else {
   %>
   <td width="35%" rowspan="1" align="center" valign=top><FONT  face="Verdana" size=2>Imagen del Lote No Disponible</FONT></td>
   <%
    } //fin del else
   %>
   </tr>
   <tr>
	<td width="18%"  class="etiqueta">&nbsp;<b><font size=1 face="Verdana">Terreno:</font></b></td>
    <td width="20%" class="etiquetasinfondo">&nbsp;<b><font size=1 color="#000000" face="Verdana"><%=clave%></font></b></td>
  </tr>
  <tr>
    <td width="27%"  class="etiqueta">&nbsp;<b><font size=1 face="Verdana">Superficie Total:</font></b></td>
    <td width="35%" class="etiquetasinfondo">&nbsp;<b><font size=1 color="000000" face="Verdana"><%=Double.parseDouble(superficie.trim())%></font></b>
	          <b><font size=1 color="000000" face="Verdana"> mts 2</font></b></td>
  </tr>
  <tr>
    <td colspan="3">
	 <table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
	 <tr>
    <td colspan="4">&nbsp;</td>
    </tr>
  <tr>
    <td colspan="4" class="titulos">&nbsp;<b><font size=2 >Medidas y Colindancias</font></b></td>
    </tr>
  <tr>
    <td  class="etiqueta" width="23%"><b><font size="2" >Norte</font></b></td>
    <td width="21%" class="etiquetasinfondo"><b><font size=1 color="000000" ><%=medid_norte%></font></b>
	                <b><font size=1 color="000000" > Mts</font></b></td>
    <td width="24%"  class="etiqueta">&nbsp;<b><font size="2" >Colinda :</font></b></td>
    <td width="32%" class="etiquetasinfondo"><b><font size=1 color="000000" ><%=mlcon_norte%></font></b></td>
  </tr>
  <tr>
    <td  class="etiqueta"><b><font size="2" >Sur:</font></b></td>
    <td class="etiquetasinfondo"><b><font size=1 color="000000" ><%=medid_sur%></font></b>
	    <b><font size=1 color="000000" > Mts</font></b></td>
    <td  class="etiqueta">&nbsp;<b><font size="2" >Colinda:</font></b></td>
    <td class="etiquetasinfondo"><b><font size=1 color="000000" ><%=mlcon_sur%></font></b></td>
  </tr>
  <tr>
    <td  class="etiqueta"><b><font size="2" >Oriente:</font></b></td>
    <td class="etiquetasinfondo"><b><font size=1 color="000000" ><%=medid_oriente%></font></b>
	    <b><font size=1 color="000000" > Mts</font></b></td>
    <td  class="etiqueta">&nbsp;<b><font size="2"  >Colinda:</font></b></td>
    <td class="etiquetasinfondo"><b><font size=1 color="000000" ><%=mlcon_oriente%></font></b></td>
  </tr>
  <tr>
    <td  class="etiqueta"><b><font size="2" > Poniente:</font></b></td>
    <td class="etiquetasinfondo"><b><font size=1 color="000000" ><%=medid_poniente%></font></b>
	    <b><font size=1 color="000000" > Mts</font></b></td>
    <td  class="etiqueta">&nbsp;<b><font size="2" >Colinda:</font></b></td>
    <td class="etiquetasinfondo"><b><font size=1 color="000000" ><%=mlcon_poniente%></font></b></td>
  </tr>
</table>

	</td>
    </tr>
</table>

	</td>
  </tr>
  <tr>
	<td>

	<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
  	<td bgcolor="#FFFFFF" class="etiqueta">
	  
	  <%if ( (statusVtas=="L" || statusVtas.equals("L") ) ) { 
	 			Statement stmt_prospectos = ConnRs.createStatement();
				ResultSet rs_prospectos = stmt_prospectos.executeQuery("select * from c_prospecto p, c_prospecto_desarrollo pd where p.id_prospecto = pd.id_prospecto and pd.cvevendedor = '"+CveVendedor+"' and pd.CveDesarrollo='"+fracc+"'");
	  	   		if( rs_prospectos.next() ){
					if( !bloqueado ){
	  %>
			  <div align="center"><font face="Verdana" size="2"><strong><a href="#" onClick="HacerCotizacionPaso2();"><b>Hacer Cotizaci&oacute;n
	        (Lote Libre)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      </b></a></strong></font></a></div>
			  
		      <% 
				}else{%>
				<div align="center"><b><font color="#FF0000" size="2" face="Verdana">
				  Lote Bloqueado!!!
				  </font></b></div>
<%}
				}else{  %>
				<div align="center"><b><font color="#FF0000" size="2" face="Verdana">
				  No hay prospectos asigandos a este desarrollo para el vendedor!!!
				  </font></b></div>
		        <%	}
		}else{%>
			<div align="center"><b><font color="#FF0000" size="2" face="Verdana">
		<%	if( statusVtas.equals("V") )out.println("Vendido");
				else if( statusVtas.equals("C") )out.println("Contratado");
				else if( statusVtas.equals("A") )out.println("Apartado");
				else if( statusVtas.equals("I") )out.println("Intercambio");
			  %>!!!
			  </font></b></div>
		<%}%>
    </td>
	</tr>
	</table>	  
	  
    </td>
  </tr>
</table>
<%
//}
%>
<INPUT name=ClaveT type=hidden value=<%=clave%>>
<INPUT name=NTerreno type=hidden value=<%=no_terreno%>> 
<INPUT name=Superficie type=hidden value=<%=Double.parseDouble(superficie.trim())%>>
<INPUT name=PrecioM2Base type=hidden value=<%=Double.parseDouble(precio_m2.trim())%>>
<INPUT name=PrecioTotal type=hidden value=<%=(Double.parseDouble(precio_m2.trim())* Double.parseDouble(superficie.trim()) )%>>
<INPUT name=Status type=hidden value=Nuevo>
<INPUT name=Med_norte type=hidden value=<%=medid_norte%>>
<INPUT name=Med_sur type=hidden value=<%=medid_sur%>>
<INPUT name=Med_ori type=hidden value=<%=medid_oriente%>>
<INPUT name=Med_pon type=hidden value=<%=medid_poniente%>>
<INPUT name=Mlcon_norte type=hidden value=<%=mlcon_norte%>>
<INPUT name=Mlcon_sur type=hidden value=<%=mlcon_sur%>>
<INPUT name=Mlcon_ori type=hidden value=<%=mlcon_oriente%>>
<INPUT name=Mlcon_pon type=hidden value=<%=mlcon_poniente%>>
</FORM>
</BODY>
</HTML>
<%
Rsquery.close();
StatementRs.close();
ConnRs.close();
%>